<?php
 
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Hash;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class PerformanceController extends Controller
{
	//=========================显示=====================
    public function getIndex(Request $request){
    	//查询分页
	    	if($request['name']){
	    		//搜索分页
	    		$res = DB::table('performance')
                ->join('person','Performance.PersonID','=','person.id')
                ->where('PersonName','like','%'.$request['name'].'%')
                 ->select('performance.*','PersonName')
                ->paginate(1);
	    	}else{
	    		//查询所有分页
	    		$res = DB::table('person')
                ->join('performance','performance.PersonID','=','person.id')
                ->select('person.PersonName','performance.PerformanceID','performance.Efficiency','performance.Attitude')
                ->paginate(1);
	    	}
            //dd($res);
	    $info = $request -> all();
    	
    	//解析列表模板页面
	    return view('Personnel/Performance/index',['res'=>$res,'info'=>$info]);
    }
    //=================================编辑=====================
    public function getEdit($PerformanceID){
        //根据id查询数据信息
        $info= DB::table('performance')
        ->join('person','person.id','=','performance.personID')
        ->where('PerformanceID',$PerformanceID)
        ->select('performance.*','person.id','person.PersonName')
        ->get();
        //dd($info);
    	//解析模板显示编辑的页面
        	return view('Personnel/Performance.edit',['info'=>$info,'PerformanceID'=>$PerformanceID]);
    }
    //================执行编辑
    public function postUpdate(Request $request){
        $info = $request ->all();
        //dd($info);
        $PerformanceID = $info['PerformanceID'];
        //dd($info);
        DB::table('performance')
        ->join('person','person.id','=','Performance.personID')
        ->where('PerformanceID',$PerformanceID)->update($info);
        return redirect('Personnel/Performance/index')->with('修改成功');
    }
    public function getAdd(){
       
        $res = DB::table('person')->select('PersonName','id')->get();
        //解析视图模板
        return view('Personnel/Performance/add',['res'=>$res]);
        //
    }   
    public function postInsert(Request $request){
        //接收数据
        $data = $request ->all();
        //dd($data);
        //执行插入语句
        $res  = DB::table('performance')->insert($data);
        //判断
        if($res){
            //跳转至列表页
            return redirect('Personnel/Performance/index')->with('success','添加成功');
        }else{
            return back() ->with('error','添加失败');
        }
    }
   







}
?>